/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
 * Fade Slider Toggle plugin
 * 
 * Copyright(c) 2009, Cedric Dugas
 * http://www.position-relative.net
 *	
 * A sliderToggle() with opacity
 * Licenced under the MIT Licence
 */

var $jq = jQuery.noConflict();

$jq.fn.fadeSliderToggle = function(settings) {
 	 settings = jQuery.extend({
		speed:350,
		easing : "swing"
	}, settings)
	
	$jq(this).animate({
		opacity: 'toggle',
		height: 'toggle'
	}, settings.speed, settings.easing);
}; 

//plugin arranged by azurenote


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var ism_Last;

//entry point
function azurenote_ism(setting_path)
{
	var param = {
		url: setting_path,
		dataType: '',
		contentType: '',

		success: function(data,msg)
		{
			if($jq.browser.msie)
			{
				eval('var jsondata = ' + data + ';');
				data = jsondata;
			}

			azurenote_ism_invoke(data);
		},
		error:function(data,msg)
		{
			alert(msg);
		},
		beforeSend:function(xhr) {
			xhr.setRequestHeader("Referer", '');
			xhr.setRequestHeader('Origin',null);
			xhr.setRequestHeader('If-None-Match','0');
		}
	}

		param.dataType = 'html';
		param.contentType = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
	$jq.ajax(param);
/*new Ajax.Request(setting_path,
  {
    method:'get',
	contentType: 'text/html,application/xhtml+xml,application/xml;',
    onSuccess: function(transport){
      var response = transport.responseText || "no response text";
      alert("Success! \n\n" + response);
    },
    onFailure: function(){ alert('Something went wrong...') }
  });
*/

}

function azurenote_ism_invoke(setting)
{
	if (!setting)
		return;

	var imageset = setting[Math.floor(Math.random()*(setting.length))];

	if($jq.browser.msie)
	{
		$jq(function(){
			azurenote_ism_setup(imageset);
		});
	}
	else
		azurenote_ism_setup(imageset);
}

function azurenote_ism_setup(imageset)
{
	//setup toggle
	$jq('.ismMenuImageHeader')
		.each(function(index,item) {
				$jq(this).attr("src", imageset[index]);
			})
		.click(function(event) {
				if (this == event.target)
				{
					if (ism_Last)
					{
						$jq(ism_Last).next().fadeSliderToggle();

						if (ism_Last == this)
						{
							ism_Last = null;
							return false;
						}
					}

					$jq(this).next().fadeSliderToggle();
					ism_Last = this;
				}
				return false;
			})

		.next().hide();
}
